const path = require('path');
const fs = require('fs');
export async function getFiles(folderPath, type, mothod) {
  let files = [];
  if (mothod === 'openFile') {
    files = [...folderPath];
  } else if (mothod === 'multiSelections') {
    files = [...folderPath];
  } else if (mothod === 'openDirectory') {
    const names = fs.readdirSync(folderPath[0]);

    files = names.map((file) => {
      const filePath = path.join(folderPath[0], file);

      return filePath;
    })
  }
  const imageFiles = files.filter((file) => {
    const fileExtension = path.extname(file).toLowerCase();

    if (type === 'img') {
      return ['.png', '.jpg', '.jpeg', '.bmp'].includes(fileExtension);
    }
  })
  const images = imageFiles.map((file) => {
    const name = file.split('\\').pop();
    return {
      name: name,
      path: file
    }
  })
  return images;
}